function checkLogin(){
	$.ajax({
		async: false,
		url:"/CMU/login",
		type: "GET",
		data: "username="+$('#loginusername').val()+"&password="+$('#loginpassword').val(),
		dataType: "json",
		success:function(data){
				if(userID>0){
					localStorage.setItem("username",$('#loginusername').val());
					localStorage.setItem("userID",data.userID);
					localStorage.setItem("authToken",data.authToken);
					setHeader();				
				}
		},
		error:function(jqXHR,textStatus,errorThrown){
			}
	});
};

function setHeader(){
	$("#header").html(
			"<div style=\"font-size: 1em;top:0;left: 0; padding-left: 5px;padding-top: 5px;position:absolute;\"><span style=\"font-weight: bold;\">CMUBiS</span>|<a href=\"/CMU/index-html5.html\">Home</a></div><div style=\"font-size: 1em;top:0;right: 0; padding-right: 5px;padding-top: 5px;position:absolute;\">Welcome, "+localStorage.getItem("firstName")+"|<a href=\"#\">Buy</a>|<a href=\"#\">Sell</a>|<a href=\"#\">My Account</a>|<a href=\"#\">Help</a></div>"
);
	
};

function userLogout(){
	localStorage.setItem("emailAddress","example@example.com");
	clearFields();
	$.ajax({
		url: localStorage.getItem("signoutURL"),
		type: "GET",
		success:function(data){checkLogin();location.reload();},
		error:function(jqXHR,textStatus,errorThrown){
			//alert(errorThrown);
			}
	});
		
};

function clearFields(){
	$('#edit_profile_id').val("");
	$('#edit_profile_name').val("");
	$('#edit_profile_company').val("");
	$('#edit_profile_email').val("");
	$('#edit_profile_phonenumber').val("");
	$('#edit_profile_faxnumber').val("");
	$('#edit_profile_address').val("");
	$('#edit_profile_address2').val("");
	$('#edit_profile_website').val("");
	updateServicesUL();
};